<?php
/**
 * Action Plugin: Inserts a button into the toolbar to add file tags
 *
 * @author F.Schonack
 */
 
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once (DOKU_PLUGIN . 'action.php');
 
class action_plugin_codebutton2 extends DokuWiki_Action_Plugin {
 

 
    /**
     * Register the eventhandlers
     */
    function register(&$controller) {
	if (file_exists(DOKU_PLUGIN . "codebutton2/config.ini")) {
        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array ());
		}
    }
	


	function parse_ini()
	{
		$ini_array = parse_ini_file(DOKU_PLUGIN."codebutton2/config.ini");
		$list_array = array();
		foreach ($ini_array as $key => $value)
		{
			$list_array[] =  array(
                    'type' => 'format',
                    'title' => $key,
                    'icon' => '../../plugins/codebutton2/genpng.php?text='.$key,
                    'open' => '<code '.$value.'>\n',
                    'close' => '\n</code>'
                );
		}
		return $list_array;
	}    
 
    /**
     * Inserts the toolbar button
     */


    function handle_toolbar(& $event, $param) {
		$list_array = $this->parse_ini();
        $event->data[] = array (
            'type' => 'picker',
            'title' => $this->getLang('insertcode'),
            'icon' => '../../plugins/codebutton2/genpng.php?text=Code%20',
            'list' => $list_array  ,

        );
    }
 
}
